nth root algorithm